<template>
  <template v-if="user">
    <van-cell title="头像" is-link to="/user/edit" @click="toEdit('avtarUrl','头像' ,user.avtarUrl)">
      <img style="height: 48px" slot="placeholder" :src="user.avtarUrl" alt=""/>
    </van-cell>
    <van-cell title="昵称" is-link to="/user/edit" :value="user.username"
              @click="toEdit('username','昵称' ,user.username)"/>
    <van-cell title="账号" :value="user.userAccount"/>
    <van-cell title="性别" is-link to="/user/edit" :value="user.gender" @click="toEdit('gender','性别' ,user.gender)"/>
    <van-cell title="电话" is-link to="/user/edit" :value="user.phone" @click="toEdit('phone','电话' ,user.phone)"/>
    <van-cell title="邮箱" is-link to="/user/edit" :value="user.email" @click="toEdit('email','邮箱' ,user.email)"/>
    <van-cell title="星球编号" :value="user.plantcode"/>
    <van-cell title="注册时间" :value="user.createTime.toLocaleString()"/>

  </template>

</template>


<script setup lang="ts">
import {useRouter} from "vue-router";
import {onMounted} from "vue";
import {ref} from 'vue';
// import myAxios from "../../plugins/myAxios.ts";
// import {showSuccessToast, showFailToast} from "vant";
// import {getCurrentUserState} from "../../states/user.ts";
import {getCurrentUser} from "../../services/user.ts";

// const user = {
//   id: 1,
//   username: '刘秋耀',
//   userAccount: 'lqy',
//   avtarUrl: 'https://fastly.jsdelivr.net/npm/@vant/assets/logo.png',
//   gender: '男',
//   phone: '13054424198',
//   email: 'lqy@qq.com',
//   plantcode: '12345678',
//   tags: ['java', 'c++'],
//   createTime: new Date()
// }

const user = ref()


onMounted(async () => {
//   const res = await myAxios.get('/user/current')
//   console.log("res:")
//   console.log(res)
// // @ts-ignore
//   if (res.code === 0 && res.data) {
//     showSuccessToast("获取用户信息成功")
//     user.value = res.data
//   } else {
//     showFailToast('获取用户信息失败')
//   }

  user.value = await getCurrentUser()
})


const router = useRouter();

const toEdit = (editkey: string, editName: string, currentValue: string) => {
  router.push({
    path: '/user/edit',
    query: {
      editkey: editkey,
      editName: editName,
      currentValue: currentValue
    }
  });
}


</script>

<style scoped>

</style>